from IPython.display import HTML, display, Image
# set path containing data folder or use default for Colab (/gdrive/My Drive)
local_folder = "../"
import urllib.request
urllib.request.urlretrieve('https://raw.githubusercontent.com/guiwitz/DLImaging/master/utils/check_colab.py', 'check_colab.py')
from check_colab import set_datapath
colab, datapath = set_datapath(local_folder)
13. Segmentation¶
Unitl now we have only explored and trained with neural networks designed for classification. Another major application of neural networks in imaging is segmentation, the dense (each pixel assigned to a class) labelling of images. Segmentation is widely used in many areas, in paticular in biomedical research (e.g. tumor segmentation) and geography (identification of buildings, fields etc.).
Changes compared to classification¶
The main difference with classification is that the output of the neural network is not a list of weights for each category but an actual image with the same size as the original. Therefore we also have to change the way we calculate the loss. For example if we want to segment our image into three categories, e.g. triangle, disk, background, we will get for each pixel a list of 3 elements on which to apply cross entropy loss as before. These 3 values are still organised into image, with each output image corresponding a probability map of a given label, as illustrated below.
HTML(datapath.joinpath('illustrations/segmentation.html').as_posix())